package com.znzz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znzz.dao.UserDao;
import com.znzz.domain.User;
import com.znzz.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务实现层
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements IUserService {
    @Autowired
    private UserDao userDao;

    @Override
    public void add() {
        User user = new User();
        userDao.insert(user);
    }

    @Override
    public IPage<User> getPage(int currentPage, int pageSize) {
        IPage<User> page = new Page<>(currentPage, pageSize);
        return userDao.selectPage(page, null);
    }

    @Override
    public IPage<User> getPage(int currentPage, int pageSize, User user) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.like(!user.getId().isEmpty(), User::getId, user.getId());
        lqw.like(!user.getName().isEmpty(), User::getName, user.getName());
        lqw.like(!user.getAddress().isEmpty(), User::getAddress, user.getAddress());
        IPage<User> page = new Page<>(currentPage, pageSize);
        return userDao.selectPage(page, lqw);
    }
}
